package com.design.pattern.observer;

public class ForecastDisplay implements Observer, DisplayElement {

    private Subject weatherData;
    private float temp;
    private float humidity;
    private float pressure;

    public ForecastDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    public void display() {
        System.out.println("ForecastDisplay 当前温度：" + temp + "F; 湿度为：" + humidity + "%; 气压为:" + pressure);
    }

    public void update(float temp, float humidity, float pressure) {
        this.temp = temp;
        this.humidity = humidity;
        this.pressure = pressure;
        display();
    }
}